package Excepton;

import java.util.Scanner;

public class Demo3 {
    public static void main(String[] args) {
        try {
            login();
        } catch (AccountException e) {
            System.out.println("异常错误代码"+e.getCode());
            if(e.getCode()==530){
                UsernameException usernameException=new UsernameException();
                usernameException.initCause(e).printStackTrace();
            }
            if(e.getCode()==531){
                PasswordException passwordException=new PasswordException();
                passwordException.initCause(e).printStackTrace();
            }
        }
    }
    public static void checkusername(String username){
//        if(username==null){
//            throw new UsernameException();
//        }
        if(username.length()<6){
            throw new UsernameException();
        }
//        if(username.contains("a")){
//            throw new UsernameException(532,"账号存在非法字符");
//        }
    }
    public static void checkpassword(String password){
//        if(password==null){
//            throw new UsernameException();
//        }
        if(password.length()<6){
            throw new UsernameException();
        }
//        if(password.contains("a")){
//            throw new UsernameException(534,"密码存在非法字符");
//        }
    }
    public static void login(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你的账号");
        String username=sc.next();
        System.out.println();
        System.out.println("请输入你的密码");
        String password=sc.next();
        checkusername(username);
        checkpassword(password);
        System.out.println("登录成功");
    }
}
